﻿using System;
using System.IO;

namespace 历史记录
{
    public class HistoryInfo
    {
        /// <summary>
        /// 默认数据存放地址
        /// </summary>
        public static readonly string DefaultPath = Path.Combine(Environment.CurrentDirectory, "History");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="path">数据储存目录</param>
        /// <param name="dal">数据库访问层</param>
        /// <param name="bll">业务逻辑层</param>
        /// <param name="lengh">默认长度 超出长度保存数据  默认一千条</param>
        /// <param name="timeout">默认超时 单位秒 默认五分钟</param>
        /// <param name="save">保存天数默认保存五天</param>
        /// <param name="delete">默认删除间隔 五分钟</param>
        public HistoryInfo(string path = null, DAL dal = DAL.LiteDBC, BLL bll = BLL.Single, int lengh = 1000, TimeSpan? timeout = null, TimeSpan? save = null, TimeSpan? delete = null)
        {
            if (string.IsNullOrEmpty(path))
                ConnectionPath = DefaultPath;
            else ConnectionPath = path;
            if (!Directory.Exists(ConnectionPath)) Directory.CreateDirectory(ConnectionPath);
            BLLType = bll;
            DALType = dal;
            DefaultLengh = lengh;
            if (timeout != null && timeout.HasValue)
                DefaultTimeout = timeout.Value;
            else DefaultTimeout = new TimeSpan(TimeSpan.TicksPerMinute * 5);

            if (save != null && save.HasValue)
                SaveSpan = save.Value;
            else SaveSpan = new TimeSpan(TimeSpan.TicksPerDay * 5);

            if (delete != null && delete.HasValue)
                DeleteSpan = delete.Value;
            else DeleteSpan = new TimeSpan(TimeSpan.TicksPerMinute * 5);
        }

        /// <summary>
        /// 数据储存目录
        /// </summary>
        public string ConnectionPath { get; }

        /// <summary>
        /// 默认长度 超出长度保存数据  默认一千条
        /// </summary>
        public int DefaultLengh { get; }

        /// <summary>
        /// 默认超时 单位秒 默认五分钟
        /// </summary>
        public TimeSpan DefaultTimeout { get; }

        /// <summary>
        /// 保存天数默认保存五天
        /// </summary>
        public TimeSpan SaveSpan { get; }

        /// <summary>
        /// 默认删除间隔 五分钟
        /// </summary>
        public TimeSpan DeleteSpan { get; }

        /// <summary>
        /// 存储类型
        /// </summary>
        public BLL BLLType { get; }

        /// <summary>
        /// 数据库类型
        /// </summary>
        public DAL DALType { get; }
    }

    /// <summary>
    /// 业务逻辑层
    /// </summary>
    public enum BLL
    {
        Single,
        Submeter
    }

    /// <summary>
    /// 数据访问层
    /// </summary>
    public enum DAL
    {
        LiteDBC,
        SqlIteSugar,
    }
}